<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
    <head>
        <script type="text/javascript" src="sclmenu.js"></script>
        <link rel="stylesheet" type="text/css" href="cssource.css">

        <title>Arcata Waste Water Marsh Modeling Project</title>

        <?php
            
            $months=array("January","February","March","April","May","June","July","August","September","October","November","December");
            $misc=array("inflow","TWE","precip");
            $fore=array("inflowd1","inflowd2","precipd1","precipd2","days");
            $ponds=array("Ox1","Ox2","Ox3","TM1","TM2","TM3","TM4","Chlorine","Allen","Gearheart","Hauser","Brackish","Bay");

            $data=array("inflow0","inflow1","inflow2","inflow3","inflow4",
                        "precip0","precip1","precip2","precip3","precip4",
                        "month0","month1","month2","month3","month4",
                        "year0","year1","year2","year3","year4",
                        "day0","day1","day2","day3","day4",);

            $routes=array("Ox2_TM1_1","Ox2_TM1_2","Ox2_TM2_1","Ox2_TM2_2",
                        "Ox3_TM3","Chl_Allen","Chl_Bay");

            $pumps=array("Ox3_Chl_1","Ox3_Chl_2","Ox3_Chl_3");

            $pumpDescriptor=array(
            "Ox1_Ox2_West"          =>"Ox2 to Ox3 (West)",
            "Ox1_Ox2_East"          =>"Ox2 to Ox3 (East)",
            "Ox2_TM1_1"             =>"Ox2 to TM1 (1)",
            "Ox2_TM1_2"             =>"Ox2 to TM1 (2)",
            "Ox2_TM2_1"             =>"Ox2 to TM2 (1)",
            "Ox2_TM2_2"             =>"Ox2 to TM2 (2)",
            "Ox2_Ox3_North"         =>"Ox2 to Ox3 (North)",
            "Ox2_Ox3_South"         =>"Ox2 to Ox3 (South)",
            "Ox2_Ox2Box"            =>"Ox2 to Stilling Tower",
            "Ox2Box_TM4"            =>"Stilling Tower to TM4",
            "Ox3_TM3"               =>"Ox3 to TM3",
            "Ox3_Chl_1"             =>"Ox3 to Ox3 Well",
            "Ox3_Chl_2"             =>"Ox3 Well to Chlorine Contact",
            "Ox3_Chl_3"             =>"Ox2 to Chlorine Contact",
            "TM1_TBox"              =>"TM1 to TBox",
            "TBox_Chl"              =>"TBox to Chlorine Contact Basin",
            "TM2_TBox_MSouth"       =>"TM2 to TBox (Most South)",
            "TM2_TBox_South"        =>"TM2 to TBox (South)",
            "TM2_TBox_North"        =>"TM2 to TBox (North)",
            "TM2_TBox_MNorth"       =>"TM2 to TBox (Most North)",
            "TM3_TBox_MWest"        =>"TM3 to TBox (Most West)",
            "TM3_TBox_West"         =>"TM3 to TBox (West)",
            "TM3_TBox_East"         =>"TM3 to TBox (East)",
            "TM3_TBox_MEast"        =>"TM3 to TBox (Most East)",
            "TM4_TM1"               =>"TM4 to TM1",
            "Chl_Allen"             =>"Chlorine Contact to Allen",
            "Allen_Gearheart_1"     =>"Allen to Gearheart (1)",
            "Allen_Gearheart_2"     =>"Allen to Gearheart (2)",
            "Allen_Gearheart_3"     =>"Allen to Gearheart (3)",
            "Gearheart_Hauser_Small"=>"Gearheart to Hauser (Small)",
            "Gearheart_Hauser_Big"  =>"Gearheart to Hauser (Big)",
            "Hauser_Brackish"       =>"Hauser to Brackish",
            "Hauser_Chl"            =>"Hauser to Chlorine Contact Basin",
            "Chl_Bay"               =>"Chlorine Contact Basin to Bay"      );

            if (file_exists('tmp/pondSim/pondSim.log')){
                $POST['Log_File']=file('tmp/pondSim/pondSim.log');
            }
//            echo system("kill 14211");

            if($_POST){

                if ($_POST["Current_Page"]==1)
                    loadData();


                foreach ($routes as $val){
                    $_POST[$val]=array("Weir_Height","Box_Top","Difference");
                    $_POST[$val]['Weir_Height']=$_POST["".$val."_Weir_Height"];
                    $_POST[$val]['Box_Top']=$_POST["".$val."_Box_Top"];
                    $_POST[$val]['Difference']=$_POST["".$val."_Difference"];
                }

                foreach ($pumps as $val){
                    $_POST[$val]=array("Current_Value","List","Hours","Offset");
                    $_POST[$val]["Current_Value"]=$_POST["".$val."_Current_Value"];
                    $_POST[$val]["Hours"]=$_POST["".$val."_Hours"];
                    $_POST[$val]["Offset"]=$_POST["".$val."_Offset"];
                    for ($c=0;$c<3;$c++){
                        $_POST[$val]['List'][]=$_POST["".$val."_List_".$c];
                    }
                }

            }else{
                $_POST['days']=1;
                $_POST['This_is_EXTREEMELY_IMPORTANT']=0;

                $_POST["Current_Page"]=1;
                loadData();
                loadFiles();

                $_POST['inflow']=$_POST['inflow2'];
                $_POST['inflowd1']=$_POST['inflow3'];
                $_POST['inflowd2']=$_POST['inflow4'];
                $_POST['P2SP']=0;
                $_POST['TWE']=1.5;
                $_POST['precip']=$_POST['precip2'];
                $_POST['precipd1']=$_POST['precip3'];
                $_POST['precipd2']=$_POST['precip4'];

//***************************************************************
//
//              Setting Pumping Values
//
//***************************************************************

                $_POST['Ox3_Chl_1']=array("Current_Value"=>2,"List"=>array(0,2,4),"Hours"=>0,"Offset"=>0);
                $_POST['Ox3_Chl_2']=array("Current_Value"=>1.5,"List"=>array(0,1.5,2.4),"Hours"=>0,"Offset"=>0);
                $_POST['Ox3_Chl_3']=array("Current_Value"=>4.2,"List"=>array(0,4.2,5.8),"Hours"=>0,"Offset"=>0);


                $_POST["modelRunning"]=0;
            }

            if ($_POST["modelRunning"]==1 && $_POST['This_is_EXTREEMELY_IMPORTANT']==0){
                $_POST['This_is_EXTREEMELY_IMPORTANT']=1;
                $f=fopen("input/inflow",'w') or die("Can't open file");
                fwrite($f,''.$_POST['inflow']."\n");
                for($c=0;$c<$_POST['days']-1;$c++)
                    fwrite($f,''.$_POST['inflowd'.($c+1)]."\n");
                fclose($f);
                $f=fopen("input/precip",'w') or die("Can't open file");
                fwrite($f,''.$_POST['precip']."\n");
                for($c=0;$c<$_POST['days']-1;$c++)
                    fwrite($f,''.$_POST['precipd'.($c+1)]."\n");
                fclose($f);

                $f=fopen("input/pond.surf",'w') or die ("Can't open file");
                foreach ($ponds as $val){
                    if (strcmp($val,"Ox3")!=0)
                        fwrite($f,''.$_POST[$val]."\n");
                }
                fclose($f);

                system("cp params/con.crest params/con.crest.tmp");
                system("chmod -R 777 tmp/pondSim ");

                $f=fopen("params/con.crest.tmp",'r');
                $g=fopen("params/con.crest",'w');
                while ($info=fscanf($f,"%f %s %s %s %s %s %s %s %s %s")){
                    for ($c=0;$c<9;$c++){
                        if ($c==0 && $info[2]=="#")
                            fwrite($g,''.$info[$c].'    ');
                        elseif ($c==0 && $info[2]!="#")
                            fwrite($g,''.$_POST[$info[2]]["Weir_Height"].'    ');
                        else
                            fwrite($g,''.$info[$c].'  ');
                    }
                    fwrite($g,"\n");
                }
                fclose($f);
                fclose($g);

                system("cp tmp/pondSim/params/con.pump tmp/pondSim/params/con.pump.tmp");
                $tmp=array(0=>0,1=>0,2=>0);

                $f=fopen("params/con.pump.tmp","r");
                $g=fopen("params/con.pump","w");
                while ($info=fscanf($f,"%f %s %s %s %s %s %s %s %s %s %s %s %s %s")){
                    if ($info[2]=="#"){
                        for ($c=0;$c<13;$c++){
                            fwrite ($g,''.$info[$c].'   ');
                        }
                        fwrite($g,"\n");
                        $info=fscanf($f,"%f %s %s %s %s %s %s %s %s %s %s %s %s %s");
                        fwrite($g,$info[0]);
                        for ($c=1;$c<13;$c++){
                            fwrite ($g,''.$info[$c].'   ');
                        }
                        fwrite($g,"\n");
                    }   
                    else{
                        switch(array_search($_POST[$info[2]]["Current_Value"],$_POST[$info[2]]["List"])){
                            case 0:
                                $tmp[0]=0;
                                $tmp[1]=0;
                            break;
                            case 1:
                                $tmp[0]=$_POST[$info[2]]["List"][1];
                                $tmp[1]=0;
                            break;
                            case 2:
                                $tmp[0]=$_POST[$info[2]]["List"][1];
                                $tmp[1]=$_POST[$info[2]]["List"][2];
                            break;
                        }
                        $tmp[2]=$info[2];

                        fwrite($g,''.$tmp[0].'    ');
                        for ($c=1;$c<13;$c++)
                            fwrite($g,''.$info[$c].'    ');
                        fwrite($g,"\n");
                        $info=fscanf($f,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s");
                        if ($tmp[0]!=0)
                            fwrite($g,''.$_POST[$tmp[2]]["Hours"].'/'.$_POST[$tmp[2]]["Offset"].'    ');
                        else
                            fwrite($g,'0/0    ');
                        for ($c=1;$c<13;$c++)
                            fwrite($g,''.$info[$c].'    ');

                        fwrite($g,"\n");
                        $info=fscanf($f,"%f %s %s %s %s %s %s %s %s %s %s %s %s %s");
                        fwrite($g,''.$tmp[1].'    ');
                        for ($c=1;$c<13;$c++)
                            fwrite($g,''.$info[$c].'    ');
                        fwrite($g,"\n");
                        $info=fscanf($f,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s");
                        if ($tmp[1]!=0)
                            fwrite($g,''.$_POST[$tmp[2]]["Hours"].'/'.$_POST[$tmp[2]]["Offset"].'    ');
                        else
                            fwrite($g,'0/0    ');
                        for ($c=1;$c<13;$c++)
                            fwrite($g,''.$info[$c].'    ');
                        fwrite($g,"\n");

                    }
                }
                fclose($f);
                fclose($g);


                system("R --slave --vanilla <tmp/pondSim/clear.R");
                system("R --slave --vanilla <tmp/pondSim/pondSim.R >tmp/useless.txt &");

            }

            if ($_POST['modelRunning']==2){
                system("convert tmp/pondSim/pondSim.bargraph.pdf tmp/pondSim/bargraf.png");
                global $ponds;
                loadFiles();
                $_POST['This_is_EXTREEMELY_IMPORTANT']=0;
                $_POST['modelRunning']=0;
            }
            


            function loadFiles(){
                global $ponds;
//**************************************************************
//
//              Loading Pond Surface Elevations
//
//**************************************************************

                $f=fopen('tmp/pondSim/input/pond.surf','r');$c=0;
                while($info=fscanf($f, "%f\n")){
                    $_POST[$ponds[$c]]=$info[0];
                    if ($c==1){
                        $c++;
                        $_POST[$ponds[$c]]=$info[0];
                    }
                    $c++;
                }
                fclose($f);

//**************************************************************
//
//              Loading Weir Crest Elevations
//
//**************************************************************

                $c=0;
                $f=fopen('tmp/pondSim/params/con.crest','r');
                $g=fopen('tmp/pondSim/params/con.top','r');
                while($info=fscanf($f,"%f %s %s %s %s")){
                    $ingo=fscanf($g,"%f %s %s %s %s");
                    if($info[2]!="#"){
                        $_POST[$info[2]]=array("Weir_Height","Box_Top","Difference");
                        $_POST[$info[2]]['Weir_Height']=$info[0];
                        $_POST[$info[2]]['Box_Top']=$ingo[0];
                        $_POST[$info[2]]['Difference']=$ingo[0]-$info[0];
                    }
                }
                fclose($f);
                fclose($g);

//**************************************************************
//
//              Loading PondSim Log File
//
//**************************************************************


            }



            function  loadData(){
//**************************************************************
//
//              Loading Inflow Values
//
//**************************************************************


                $f=fopen('../inflow/inflow','r');
                $Lines_From_End=0;
                $Pointer=-3;
                while($Lines_From_End<5){
                    fseek($f,$Pointer,SEEK_END);
                    if(fgetc($f)=="\n")
                        $Lines_From_End++;
                    $Pointer--;
                }

                $c=0;
                while($info=fscanf($f,"%s %s %s %s %s %s\n")){
                    if($c<3)$k=5;else $k--;
                    $_POST["inflow".$c]=sprintf('%1.2f',round(1000*(float)$info[$k])/1000);
                    $_POST["month".$c]=$info[1];
                    $_POST["year".$c]=$info[0];
                    $_POST["day".$c]=sprintf('%02s',$info[2]);
                    $c++;
                }
                fclose($f);


//**************************************************************
//
//                  Loading Rainfall Values
//
//**************************************************************

                $f=fopen('../inflow/rainfall','r');
                $Lines_From_End=0;
                $Pointer=-3;
                while($Lines_From_End<5){
                    fseek($f,$Pointer,SEEK_END);
                    if(fgetc($f)=="\n")
                        $Lines_From_End++;
                    $Pointer--;
                }

                $c=0;
                while($info=fscanf($f,"%s %s %s %s %s %s %s %s %s\n")){
                    if($c<2)$k=6; else $k--;
                    $_POST["precip".$c]=sprintf('%1.2f',round(1000*(float)$info[$k])/1000);
                    $c++;
                }
                fclose($f);
            }


        ?>

        <script type="text/javascript">
        <!--

        function check(){
            if (document.myform.modelRunning.value==2){
                document.myform.modelRunning.value=0;
                document.myform.This_is_EXTREEMELY_IMPORTANT.value=0;
            }
        }

        function getElementsByClass(searchClass,node,tag){
            var classElements=new Array();
            if (node==null)
                node=document;
            if (tag==null)
                tag='*';
            var els=node.getElementsByTagName(tag);
            var elsLen=els.length;
            var pattern=new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
            for (i=0,j=0;i<elsLen;i++){
                if (pattern.test(els[i].className)){
                    classElements[j]=els[i];
                    j++;
                }
            }
            return classElements;
        }

        function isNumber(Field_Value,Key){
            New_Value=String(Field_Value)+String(Key);
            var Valid_Characters="0123456789";
            var i=0,Number_Decimals=0;
            if (New_Value.charAt(i)=="-") i++;
            while (i<New_Value.length){
                if(New_Value.charAt(i)=="."){
                    if (Number_Decimals==0) {
                        Number_Decimals=1;
                    }
                    else{
                        return false;   
                    }
                }
                else if (Valid_Characters.indexOf(New_Value.charAt(i))==-1)
                    return false;
                i++;
            }
            return true;
        }

        function num(field,e,other,end){
            var key;
            var keychar;
            var is=true;

            if (window.event){key=window.event.keyCode;}
            else if (e){key=e.which;}
            keychar=String.fromCharCode(key);

            if (!isNumber(field.value, keychar)) is=false;
            if (key==null||key==0||key==8||key==9||key==13||key==27||key==37||key==39||(key==46) && keychar!=".")
                is=true;

            if (is && end){
                change(field,other,end);
            }

            return is;
        }

        function change(field,other,end){
            document.getElementById(other+"_Id").value=Math.round(1000*parseFloat((end-field.value)*1))/1000;
        }


        function Load(){
<?php
                foreach ($ponds as $val){
                    echo'            document.myform.'.$val.'.value='.$_POST[$val].";\n";
                }
                foreach ($routes as $val){
                    echo'            document.myform.'.$val.'_Weir_Height.value='.$_POST[$val]["Weir_Height"].";\n";
                    echo'            document.myform.'.$val.'_Box_Top.value='.$_POST[$val]["Box_Top"].";\n";
                    echo'            document.myform.'.$val.'_Difference.value='.$_POST[$val]["Difference"].";\n";

                }
        
                foreach ($pumps as $val){
                    echo'            document.myform.'.$val.'_Current_Value.value='.$_POST[$val]["Current_Value"].";\n";
                    echo'            document.myform.'.$val.'_Hours.value='.$_POST[$val]["Hours"].";\n";
                    echo'            document.myform.'.$val.'_Offset.value='.$_POST[$val]["Offset"].";\n";
                    $c=0;
                    foreach ($_POST[$val]["List"] as $var){
                        echo'            document.myform.'.$val.'_List_'.$c.'.value='.$var.";\n";
                        $c++;
                    }
                }

                foreach ($misc as $val){
                    echo'            document.myform.'.$val.'.value='.$_POST[$val].";\n";
                }
                echo'            document.myform.This_is_EXTREEMELY_IMPORTANT.value='.$_POST['This_is_EXTREEMELY_IMPORTANT'].";\n";
                echo'            document.myform.modelRunning.value='.$_POST['modelRunning'].";\n";

                foreach ($fore as $val){
                    echo'            document.myform.'.$val.'.value='.$_POST[$val].";\n";
                }

            ?>
            check();
        }

        function spage(i,v,p){
            if ((<?=$_POST["Current_Page"]?> !=i && <?=$_POST["modelRunning"]?> !=1) || v==1){
                document.myform.modelRunning.value=p;
                document.myform.Current_Page.value=i;
                document.myform.submit();
            }
        }

        (function(){
            var menu1=new Scl.Menu(180);
            menu1.addItem('Jordan Pierce','mailto:jsp26@humboldt.edu?subject=Marsh Project');
            menu1.addItem('Cameron Bracken','mailto:cameron.bracken@humbolde.edu?subject=Marsh Procjet');
            menu1.addItem('Neil Berezovsky','mailto:nir.berezovsky@humboldt.edu?subject=Marsh Project');
            menu1.addItem('Amelia Dillon','mailto:amelia.robin@gmail.com?subject=Marsh Project');
            menu1.addItem('Jason Roberts','mailto:jasonroberts53@gmail.com?subject=Marsh Project');
            menu1.dockTo('contacts');
        })();

        onerror=handleError;
        function handleError(msg,url,line){
            var txt="An error has occured on this page.\n\n";
            txt+="Error: "+msg+"\n";
            txt+="URL: "+url+"\n";
            txt+="Line: "+line+"\n";
            alert(txt);
        }

        function imgopac(name,id,height,low,high){
            range=(high-low);
            prc=(height-low)/range;
            prc=prc*4;
            if (prc<0) prc=0;
            if (prc>5) prc=5;

            back=new Array("_Blue.gif","_Teal.gif","_Green.gif","_Yellow.gif","_Red.gif");
            set=Math.floor(prc);
            alp=prc-set;

            if (set<0) set=0;
            if (set>4) set=3;
            if (alp<0) alp=0;
            if (alp>1) alp=1;

            document.write('<img src="'+ name + back[set] + '" id="'+id+'">');
            document.write('<img style="-moz-opacity:'+alp+';filter:alpha(opacity='+100*alp+');" src="'+name+back[set+1]+'" id="'+id+'">');
        }


        function chgpg2(tis){
            var el=getElementsByClass("pg2pics");
            var teist=false;
            c=0;
            while(c<el.length){
                if (el[c].id!=tis)
                    document.getElementById(el[c].id).style.visibility="hidden";
                else
                    teist=true;
                c++;
            }
            if (teist)
                document.getElementById(tis).style.visibility="visible";
        } 


        -->
        </script>

    </head>

    <body onload="Load()">
        <form name="myform" action="index.php" method="post"> 

        <input type="hidden" name="Current_Page">
        <input type="hidden" name="modelRunning">
<?php
            foreach ($ponds as $val){
                echo'        <input type="hidden" name="'.$val.'"'.">\n";
            }
            foreach ($routes as $val){
                echo'        <input type="hidden" name="'.$val.'_Weir_Height"'.">\n";
                echo'        <input type="hidden" name="'.$val.'_Box_Top"'.">\n";
                echo'        <input type="hidden" name="'.$val.'_Difference"'.">\n";

            }
    
            foreach ($pumps as $val){
                echo'        <input type="hidden" name="'.$val.'_Current_Value"'.">\n";
                echo'        <input type="hidden" name="'.$val.'_Hours"'.">\n";
                echo'        <input type="hidden" name="'.$val.'_Offset"'.">\n";
                $c=0;
                foreach ($_POST[$val]["List"] as $var){
                    echo'        <input type="hidden" name="'.$val.'_List_'.$c.'"'.">\n";
                    $c++;
                }
            }

            foreach ($misc as $val){
                echo'        <input type="hidden" name="'.$val.'" >'."\n";
            }
            echo'        <input type="hidden" name="This_is_EXTREEMELY_IMPORTANT">'."\n";

            foreach ($fore as $val){
                echo'        <input type="hidden" name="'.$val.'">'."\n";
            }
        ?>


<?php 

 $f=fopen('tmp/pondSim/modelRunning','r');
 $info=fscanf($f,"%f\n");
 $status=$info[0];
 fclose($f);
 if ($_POST['modelRunning']!=1){
?>



        <div id="head">

            <table id="topHeader" cellpadding="0" cellspacing="0" border="0" height="100px" background="figs/pondSim.png" style="background-repeat:no-repeat">
                <tr><td valign="top" width="150px" height="100px">
                    <img src="figs/hand.png" height="70px" style="padding:30px 0px 0px 10px;"/>
                </td><td valign="top" width="100%" height="30px">
                    <div id="header"> 
                    &nbsp;&nbsp;Arcata Marsh Project
                    </div>
                </td></tr>
            </table>

            <table id="sideHeader" cellspacing="0" cellpadding="0" border="0" height="1100px" width="150px" >
                <tr width="150px"><td valign="top">
                    <div id="lcol">
                        <br/>
    
                        <div id="test" onclick="spage(1,0,0);" <?php if($_POST["Current_Page"]==1) echo'style="background-color:#AFC7C7"';?>>&nbsp;
                            Forecast 
                        </div>

<!--                        <div id="test" onclick="spage(2,0,0);" <?php if($_POST["Current_Page"]==2) echo'style="background-color:#AFC7C7"';?>>&nbsp;
                            Inputs
                        </div>-->

                        <div id="test" onclick="spage(3,0,0);" <?php if($_POST["Current_Page"]==3) echo'style="background-color:#AFC7C7"';?>>&nbsp;
                            Parameters
                        </div>

                        <div id="test" onclick="spage(4,0,0);" <?php if($_POST["Current_Page"]==4) echo'style="background-color:#AFC7C7"';?>>&nbsp; 
                            Rating Curves
                        </div>

                        <div id="test" onclick="spage(5,0,0);" <?php if($_POST["Current_Page"]==5) echo'style="background-color:#AFC7C7"';?>>&nbsp; 
                            Model Info
                        </div>
                        <br/> <br/> <br/> <br/> <br/> <br/>
                        <div id="Contacts">
                            &nbsp;<span id="contacts" style="cursor:pointer"> Contacts <img src="figs/ltl.gif"></span>
                        </div>

                    </div>
        

                    <div id="info">
                        This site was created by the Humboldt State University Capstone Design Team, 2008.
                        <img src="figs/HSUStackedLogo.gif" width="130px" style="padding:5px;"/>
                    </div>

                </td></tr>
            </table>
        <div id="MBody">  

<!--
Main Body Starts Here
-->


            <?php switch ($_POST["Current_Page"]){case 1:?> <!-- Put data for page 1 here -->
<!-- ######################################################
###########################################################
#
#
#                   PAGE 1
#
#
###########################################################
########################################################### -->
                <div class="PageDiv" id="pg1bdy">


                    <img src="new.php" id="pg1bar" width="900px">
                    <table id="inf"><thead><tr><th>Date</th><th>Precip</th><th>Inflow</th></tr></thead>
                        <caption>Predicted Precipitation and Inflow</caption>
      <?php 
      $c=0;
      while ($c<5){
       if($c!=2){
        echo'<tr><td>'.$months[$_POST["month".$c]-1].' '.$_POST["day".$c].'</td><td>'.$_POST["precip".$c].'</td><td>'.$_POST["inflow".$c].'</td></tr>'."\n";
       }
       else{
        echo'<tr style="background-color:snow;"><td>'.$months[$_POST["month".$c]-1].' '.$_POST["day".$c].'</td><td>'.$_POST["precip".$c].'</td><td>'.$_POST["inflow".$c].'</td></tr>'."\n";
       }
       $c++;
      }
     ?>
                    </table>
                    <br />



                    <div id="PictureWrapper">

                        <script type="text/javascript">
                            imgopac("figs/Pond1","P1",<?=$_POST['Ox1']?>,5,6);
                            imgopac("figs/Pond2","P2",<?=$_POST['Ox2']?>,5,6);
                            imgopac("figs/Pond3","P3",<?=$_POST['Ox3']?>,5,6);
                            imgopac("figs/TM1","TM1",<?=$_POST['TM1']?>,2,4);
                            imgopac("figs/TM2","TM2",<?=$_POST['TM2']?>,2,4);
                            imgopac("figs/TM3","TM3",<?=$_POST['TM3']?>,2,4);
                            imgopac("figs/TM4","TM4",<?=$_POST['TM4']?>,2,4);
                        </script>
                        <img src="figs/color_key.gif" id="color_key">
                        <div id="hi">
                        --------- High
                        </div>
                        <div id="nom">
                        --------- Nominal
                        </div>
                        <div id="low">
                        --------- Low
                        </div>
                    </div>

                <hr style="width:415px;" align="left">
                <table><tr><td align="center">Log File</td></tr><tr><td>
                <div id="log">
                <?php
                    foreach ($POST['Log_File'] as $val){
                        echo $val;echo"<br />";
                    }
                ?>
                </div></td></tr></table>
                    <div id="pg1info">
                        Forcast data are based off National Weather Service <a href="http://www.wrh.noaa.gov/forecast/wxtables/index.php">Quantitative Precipitation Forecasts</a> (QPF).
       
                    </div>


                </div>



                <?php break;case 2: ?> <!-- Put data for page 2 here -->
  

                <?php break;case 3:?> <!-- Put data for page 3 here -->

<!-- ######################################################
###########################################################
#
#
#                   PAGE 3
#
#
###########################################################
########################################################### -->

                <div id="pg2pics">
                    <img src="figs/marshes_green.gif"/>
                    <img src="figs/Ox2_TM2_Weir_2.gif"   id="Ox2_TM1_1"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox2_TM2_Weir_2.gif"   id="Ox2_TM1_2"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox2_TM2_Weir_2.gif"   id="Ox2_TM2_1"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox2_TM2_Weir_2.gif"   id="Ox2_TM2_2"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox3_TM3_Weir.gif"     id="Ox3_TM3"    class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox2_Ox2Box.gif"       id="Ox2_Ox2Box" class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/TBox_Chl.gif"         id="TBox_Chl"   class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Hauser_Chl.gif"       id="Hauser_Chl" class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Chl_Allen.gif"        id="Chl_Allen"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox3_Chl_1.gif"        id="Ox3_Chl_1"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox3_Chl_2.gif"        id="Ox3_Chl_2"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Ox2_Chl.gif"          id="Ox3_Chl_3"  class="pg2pics" style="visibility:hidden;"/>
                    <img src="figs/Chl_Bay.gif"          id="Chl_Bay"    class="pg2pics" style="visibility:hidden;"/>
                </div>
    
                <div class="PageDiv" id="pg2p">
                    <h1><u>Inputs</u></h1><br />
                    <table><tr><td width="275px">
                        Simulation Length (days):</td><td>
                        <select id="pg2s" type="select" onchange="document.myform.days.value=this.options[this.selectedIndex].value;redeye(this.selectedIndex);">
                        <option value=1 <?php if ($_POST['days']==1) echo 'selected';?>>1
                        <option value=2 <?php if ($_POST['days']==2) echo 'selected';?>>2
                        <option value=3 <?php if ($_POST['days']==3) echo 'selected';?>>3
                        </select></td></tr><tr><td width="275px">

                        Total Plant Inflow:</td><td>    
                        <input class="textfield" type="text" name="inflow" onkeypress="return num(this,event);" id="TPI_ID" value="<?=$_POST['inflow']?>"/>
                        </td></tr><tr id="day1" style="visibility:hidden;position:absolute"><td width="275px">

                        Total Plant Inflow Day 2:</td><td>    
                        <input class="textfield" type="text" name="inflowd1" onkeypress="return num(this,event);" id="TPId1_ID" value="<?=$_POST['inflowd1']?>"/>
                        </td></tr><tr id="day2" style="visibility:hidden;position:absolute"><td width="275px">

                        Total Plant Inflow Day 3:</td><td>    
                        <input class="textfield" type="text" name="inflowd2" onkeypress="return num(this,event);" id="TPId2_ID" value="<?=$_POST['inflowd2']?>"/>
                        </td></tr><tr><th colspan="2"><hr> </th></tr><tr><td>

                        Today's Precipitation:</td><td> 
                        <input class="textfield" type="text" name="precip" onkeypress="return num(this,event);" id="precip_ID" value="<?=$_POST['precip']?>"/></td></tr><tr id="pay1" style="visibility:hidden;position:absolute"><td width="275px">

                        Precipitation Day 2:</td><td> 
                        <input class="textfield" type="text" name="precipd1" onkeypress="return num(this,event);" id="precipd1_ID" value="<?=$_POST['precipd1']?>"/></td></tr><tr id="pay2" style="visibility:hidden;position:absolute"><td width="275px">

                        Precipitation Day 3:</td><td> 
                        <input class="textfield" type="text" name="precipd2" onkeypress="return num(this,event);" id="precipd2_ID" value="<?=$_POST['precipd2']?>"/></td></tr><tr><th colspan="2"><hr></th></tr><tr><td>

                        Target Wetland Influent:</td><td>  
                        <input class="textfield" type="text" name="TWE" onkeypress="return num(this,event);" id="WI_ID" value="<?=$_POST['TWE']?>"/><br /></td></tr><tr><td>
                    </td></tr></table>


                <script>

                    function redeye(num){
                        switch (num){
                            case 0:
                                document.getElementById('day1').style.visibility="hidden";
                                document.getElementById('day1').style.position="absolute";
                                document.getElementById('day2').style.visibility="hidden";
                                document.getElementById('day2').style.position="absolute";

                                document.getElementById('pay1').style.visibility="hidden";
                                document.getElementById('pay1').style.position="absolute";
                                document.getElementById('pay2').style.visibility="hidden";
                                document.getElementById('pay2').style.position="absolute";
                            break;
                            case 1:
                                document.getElementById('day1').style.visibility="visible";
                                document.getElementById('day1').style.position="relative";
                                document.getElementById('day2').style.visibility="hidden";
                                document.getElementById('day2').style.position="absolute";

                                document.getElementById('pay1').style.visibility="visible";
                                document.getElementById('pay1').style.position="relative";
                                document.getElementById('pay2').style.visibility="hidden";
                                document.getElementById('pay2').style.position="absolute";
                            break;
                            case 2:
                                document.getElementById('day1').style.visibility="visible";
                                document.getElementById('day1').style.position="relative";
                                document.getElementById('day2').style.visibility="visible";
                                document.getElementById('day2').style.position="relative";

                                document.getElementById('pay1').style.visibility="visible";
                                document.getElementById('pay1').style.position="relative";
                                document.getElementById('pay2').style.visibility="visible";
                                document.getElementById('pay2').style.position="relative";
                            break;
                        }
                    }
                    redeye(<?=$_POST['days']?>-1);
                </script>


                    <input type="button" value="Run Model" onclick="spage(1,1,1);car=0;" id="pg2button">

                    <hr>
                    <h1><u>Weirs</u> </h1><p> Weir heights are measured in feet from the top of the weir box</p> <br />
                    <table id="pg2table" rules="groups"><thead><tr style="font-size:small;border-bottom:1px;"><th>Description</th><th>From Top</th><th>Absolute Elevation</th></tr></thead>
      <?php foreach ($routes as $pump){
       echo "<tr><td width=\"300px\">$pumpDescriptor[$pump]: </td><td width=\"100px\">\n";
       echo '
        <input class="textfield" 
        type="text" 
        name="'.$pump.'_Weir_Height" 
        id="'.$pump.'_Weir_Height_Id" 
        value="'.$_POST[$pump]['Weir_Height'].'" 
        onkeypress="return num(this,event);" 
        onfocus="chgpg2(\''.$pump.'\');" onkeyup="change(this,\''.$pump.'_Difference\','.$_POST[$pump]['Box_Top'].');"/> 
       </td><td> 
       <input class="textfield" 
        type="text" name="'.$pump.'_Difference" 
        id="'.$pump.'_Difference_Id" 
        onkeypress="return num(this,event);" 
        value="'.($_POST[$pump]['Box_Top']-$_POST[$pump]['Weir_Height']).'" onkeyup="change(this,\''.$pump.'_Weir_Height\','.$_POST[$pump]['Box_Top'].');
        " onfocus="chgpg2(\''.$pump.'\');"/> 
       </td></tr>'."\n";
       
      } ?>
                    </table>
                    <hr>

                    <h1><u>Pumps</u></h1><p> Pumping capacities are measured in MGD  </p> <br />


                    <table id="pg2table" rules="groups">
                        <thead><tr style="font-size:small;border-bottom:1px;"><th>Description</th><th>Pump Rate</th><th>Pump Hours</th><th>Offset Hours</th></thead>
<?php foreach ($pumps as $pump){
        echo "      <tr><td width=\"300px\">$pumpDescriptor[$pump]: </td><td>\n";
        echo '      <select id="pg2s" type="select" onchange="document.myform.'.$pump.'_Current_Value.value=this.options[this.selectedIndex].value;" onfocus="chgpg2(\''.$pump.'\')">'."\n";
        $c=0;$aqs=" ";
         foreach ($_POST[$pump]['List'] as $value){
          if ($_POST[$pump]['List'][$c]==$_POST[$pump]['Current_Value']){ $aqs=' selected ';}
          else{ $aqs=' ';}
          echo '      <option value='.$value.' '.$aqs.'>'.$value."\n";
          $c++;
         }
        echo '      </select></td><td>'."\n";
        echo '      <input class="textfield" style="width:50px;" name="'.$pump.'_Hours'.'" onfocus="chgpg2(\''.$pump.'\')" value="'.$_POST[$pump]['Hours'].'" >'."\n";
        echo '      </td><td><input class="textfield" style="width:50px" name="'.$pump.'_Offset'.'" onfocus="chgpg2(\''.$pump.'\')" value="'.$_POST[$pump]['Offset'].'"></td></tr>'."\n\n\n";
        
      }
      ?>
                    </table><br /><hr>

                    <h1><u>Water Surface Elevations</u></h1><br />   

                    <table><tr><td>

                        <table> <tr><td width="275px">

                            Pond #1</td><td>
                            <input class="textfield" name="Ox1" onkeypress="return num(this,event);" id="P1_ID" onfocus="changeDescription(0);" value="<?=round($_POST["Ox1"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'"/><br /></td></tr><tr><td>
                            Pond #2</td><td>
                            <input class="textfield" name="Ox2" onkeypress="return num(this,event);" id="P2_ID" onfocus="changeDescription(1);" value="<?=round($_POST["Ox2"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>
                            Pond #3</td><td>
                            <input class="textfield" name="Ox3" onkeypress="return num(this,event);" id="P3_ID" onfocus="changeDescription(2);" value="<?=round($_POST["Ox3"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>
                            Marsh #1</td><td>
                            <input class="textfield" name="TM1" onkeypress="return num(this,event);" id="M1_ID" onfocus="changeDescription(3);" value="<?=round($_POST["TM1"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>
                            Marsh #2</td><td>
                            <input class="textfield" name="TM2" onkeypress="return num(this,event);" id="M2_ID" onfocus="changeDescription(4);" value="<?=round($_POST["TM2"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>
                            Marsh #3</td><td>
                            <input class="textfield" name="TM3" onkeypress="return num(this,event);" id="M3_ID" onfocus="changeDescription(5);" value="<?=round($_POST["TM3"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>
                            Enhancement</td><td>
                            <input class="textfield" name="Allen" onkeypress="return num(this,event);" id="E_ID" onfocus="changeDescription(6);" value="<?=round($_POST["Allen"],3)?>" style="color:#777;" onkeyup="this.carriage=1;this.style.color='#000'" /><br /></td></tr><tr><td>

                        </td></tr></table></td><td width="75in">
                    </td></tr></table>

                    <textarea id="Description" rows="5" cols="50" name="Descriptio" readonly>Hello Jordan</textarea>

                    <script type="text/javascript">

                        function summe(){
                            try{
                                var pump=eval("document.myform.P2SP_ID");
                                var we=eval("document.myform.WE_ID");
                                var pe=eval("document.myform.PE_ID");
                                var cb=eval("document.myform.CB_ID");

                                pumpval= (pump.value == "" || pump.value == ".") ?  0 : pump.value;
                                weval  = (  we.value == "" ||   we.value == ".") ? 0 : we.value;
                                peval  = (  pe.value == "" ||   pe.value == ".") ? 0 : pe.value;

                                cb.value= Math.round(1000*(parseFloat(pumpval)+parseFloat(weval)+parseFloat(peval)))/1000;
                                summer();
                            }
                            catch (err){alert(err);}
                        }


                        function summer(){
                            try{
                                    var bayDischarge=eval("document.myform.BD_ID");
                                    var wetlandInfluent=eval("document.myform.WI_ID");
                                    var cb=eval("document.myform.CB_ID");
                                    wet=wetlandInfluent.value == "" ? 0 : wetlandInfluent.value;
                                    wet=wet == "." ? 0 : parseFloat(wet);
                                    cbv=cb.value == "" ? 0 : cb.value;
                                    bayDischarge.value=Math.round(1000*(parseFloat(cbv)-parseFloat(wet)))/1000;
                            }catch(err){alert(err);}
                        }

                        changeDescription(0);

                        function changeDescription(a){
                            try{
                                var desc=[7];
                                desc[0]=" Pond #1 surface elevation measurement directions: \n   -staff guage measurement on North weir box \n    box (closest to treatment plant)";
                                desc[1]=" Pond #2 surface elevation measurement directions: \n   -staff guage measurement on \n    West marsh #2 weir box";
                                desc[2]=" Pond #3 surface elevation measurement directions: \n   -water height from outlet box top";
                                desc[3]="Marsh #1 surface elevation measurement directions: \n   -water height above NW corner box in inches";
                                desc[4]="Marsh #2 surface elevation measurement directions: \n   -staff guage measurement on \n    weir box (closest to Marsh #1)";
                                desc[5]="Marsh #3 surface elevation measurement directions: \n   -staff guage measurement on North \n    weir box (closest to treatment plant)";
                                desc[6]="Gearheart surface elevation measurement directions: \n   -staff guage measurement on \n    South West weir box";
                                document.getElementById("Description").value=desc[a];
                            }
                            catch(err){
                                    alert(err);
                            }
                        }

     
                    </script>
                </div>
  
     <?php break;case 4:?> <!-- Put data for page 4 here -->
<!-- ######################################################
###########################################################
#
#
#                   PAGE 4
#
#
###########################################################
########################################################### -->
                <table id="pg4table" rules="groups"><thead><tr style="font-size:small;border-bottom:1px;"><th>Pond</th><th>Head</th><th>W-TM1</th><th>W-TM2</th><th>Q-TM1</th><th>Q-TM2</th><th>Q Total</th></tr></thead>
                    <tr><td>Ox2: 
                    </td><td>
                        <input class="textfield" name="Ox2_Head" id="Ox2_Head_Id" value="6.0" onkeypress="return num(this,event);" onkeyup="popu();"></td><td> 
                        <input class="textfield" name="Ox2_TM1" id="Ox2_TM1_Id" value="<?=$_POST['Ox2_TM1_1']['Weir_Height']?>" onkeypress="return num(this,event);" onkeyup="popu();"></td><td> 
                        <input class="textfield" name="Ox2_TM2" id="Ox2_TM2_Id" value="<?=$_POST['Ox2_TM2_1']['Weir_Height']?>" onkeypress="return num(this,event);" onkeyup="popu();"></td><td> 
                        <input class="textfield" name="Ox2_QTM1" id="Ox2_QTM1_Id" onkeypress="return num(this,event);" onkeyup="popu();"></td><td> 
                        <input class="textfield" name="Ox2_QTM2" id="Ox2_QTM2_Id" onkeypress="return num(this,event);"></td><td> 
                        <input class="textfield" name="Ox2_Qtot" id="Ox2_Qtot_Id" onkeypress="return false">
                    </td></tr>
                    <tr><td>
                    </td><td>
                        <input type="checkbox" name="Ox2_Head_Bullet" onclick="checkbox(this,'Ox2_Head_Id');">
                    </td><td>
                        <input type="checkbox" name="Ox2_TM1_Bullet" onclick="checkbox(this,'Ox2_TM1_Id');">
                    </td><td>
                        <input type="checkbox" name="Ox2_TM2_Bullet" onclick="checkbox(this,'Ox2_TM2_Id');">
                    </td><td>
                        <input type="checkbox" name="Ox2_QTM1_Bullet" onclick="checkbox(this,'Ox2_QTM1_Id');">
                    </td><td>
                        <input type="checkbox" name="Ox2_QTM2_Bullet" onclick="checkbox(this,'Ox2_QTM2_Id');">
                    </td><td>
                        <input type="checkbox" name="Ox2_Qtot_Bullet">
                    </td></tr>
                </table>
     
                <script type="text/javascript">
                    function checkbox(element,id){
                        if (element.checked) 
                            document.getElementById(id).className='noedit';
                        else
                            document.getElementById(id).className='textfield';

                        document.getElementById(id).readOnly=element.checked;
                    }
                    function popu(){
                        document.getElementById("Ox2_QTM1_Id").value=Math.round(1000*Math.pow(parseFloat(document.getElementById("Ox2_Head_Id").value)-parseFloat(document.getElementById("Ox2_TM1_Id").value),2.71828183))/1000;
                        document.getElementById("Ox2_QTM2_Id").value=Math.round(1000*Math.pow(parseFloat(document.getElementById("Ox2_Head_Id").value)-parseFloat(document.getElementById("Ox2_TM2_Id").value),2.71828183))/1000;
                        document.getElementById("Ox2_Qtot_Id").value=Math.round(1000*(parseFloat(document.getElementById("Ox2_QTM1_Id").value)+parseFloat(document.getElementById("Ox2_QTM2_Id").value)))/1000;
                    }
                    popu();
                </script>

                <p>Rating Curves for the wooden plank weirs such as those used in TM 1 are as follows
                </p>
                <img src="figs/rating_curve.jpg"/>
                <p>Rating Curves for the adjustable weirs used on Pond 2 are
                </p>
                <img src="figs/ratingCurve.jpg">
      

     <?php break;case 5:?> <!-- Put data for page 5 here -->
<!-- ######################################################
###########################################################
#
#
#                   PAGE 5
#
#
###########################################################
########################################################### -->

                This page will give information about the model: <br />
                <ul class="lst">
                <li><a href="#"> Who created it.</a>
                <li> Why it was created.
                <li> How it works (briefly).
                </ul>

        <?php break;} ?>

            </div>
        </form>
    </body>
</html>

<?php }else{
?>

        <script type="text/javascript">
            var winW = 630, winH = 460;

            

            var car='<img src="figs/dancing.gif">';
            document.write(car);
            window.setTimeout('refresh()',6500);
            function refresh(){
                if (<?=$status?>==0){
                    spage(1,1,1);
                }
                else{
                    spage(1,1,2);
                }
            }
        </script>
    <div>
        Model in Progress...
    <div>
</body>
</html>
<?php
}
?>
